package cglibproxy;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @Author Fish Paradise
 * @Description
 * @Date 2019/1/28  20:20
 **/
public class Xiaoming implements MethodInterceptor {
    private  Object object;

    public Object getInstance(Object o){
        this.object=o;
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(this.object.getClass());
        enhancer.setCallback(this);
        return enhancer.create();
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("开始");
        methodProxy.invokeSuper(o, objects);
        System.out.println("结束");
        return null;
    }
}
